package view;

import actor.Actor;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;

public class SelectView extends JComponent {
    private ImageIcon image;
    private JLabel imageLabel;
    private Border line = BorderFactory.createLineBorder(Color.BLACK, 2);

    public SelectView(Actor actor, boolean isPlayer) {
        String fileName = "src/image/" + actor.getImage() + ".png";
        image = new ImageIcon(fileName);
        imageLabel = new JLabel(image);
        JLabel nameLabel = new JLabel("NAME:" + actor.getName());
        JLabel lifeLabel = new JLabel("LIFE:" + actor.getLife());
        JLabel powerLabel = new JLabel("POWER:" + actor.getPower());
        JLabel speedLabel = new JLabel("SPEED:" + actor.getSpeed());
        int height;
        int width;
        String type;
        if (isPlayer) {
            width = 120;
            height = 140;
            type = "WEAPON:";
        } else {
            width = 100;
            height = 100;
            type = "ELEMENT:";
        }
        image.setImage(image.getImage().getScaledInstance(width, height, Image.SCALE_DEFAULT));
        imageLabel.setBounds(5, 5, width, height + 10);
        imageLabel.setBorder(line);

        JLabel elementLabel = new JLabel(type + actor.getType());
        int gap = 12;
        nameLabel.setBounds(5, height + gap * 2, 100, gap);
        lifeLabel.setBounds(5, height + gap * 3, 100, gap);
        powerLabel.setBounds(5, height + gap * 4, 100, gap);
        speedLabel.setBounds(5, height + gap * 5, 100, gap);
        elementLabel.setBounds(5, height + gap * 6, 100, gap);

        setBounds(0, 0, 120, 250);
        add(nameLabel);
        add(imageLabel);
        add(lifeLabel);
        add(powerLabel);
        add(speedLabel);
        add(elementLabel);
        setVisible(true);
    }
}
